package Demo1;

import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-05-30
 * Time: 10:36
 */
class Student{
    public String name = "小黄";
    public int age = 19;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {
    public static boolean isAdmin(String userId){
        return userId.toLowerCase()=="admin";
    }
    public static void main(String[] args){
        System.out.println(isAdmin("Admin"));
    }
    public static void main13(String[] args) {


        char[] val = {'a','b','c','d'};
        StringBuffer stringBuffer = new StringBuffer("hello");
        stringBuffer.append(" world");
        System.out.println(stringBuffer);
        StringBuilder stringBuilder = new StringBuilder("hello");
        stringBuilder.append(" world");
        System.out.println(stringBuilder);
        System.out.println(stringBuffer.reverse());
        stringBuffer.append(1);
        System.out.println(stringBuffer);
    }
    public static void main12(String[] args) {
//        String str = new String("name");
//        char[] ch = str.toCharArray();//将字符串转化为字符数组
//        String str1 = new String(ch);
//        System.out.println(str1);
        String s1 = new String("hello");
        String s2 = new String("hElLo");
        String s3 = new String("world");
        System.out.println(s1.equals(s2));
        System.out.println(s1.equals(s3));
        System.out.println(s3.equals(s2));//比较字符串内容
        System.out.println(s1.compareTo(s2));//比较字符串大小
        System.out.println(s1.compareTo(s3));
        System.out.println(s1.equalsIgnoreCase(s2));//忽略大小写比较
    }
    public static void main11(String[] args) {
        String str = "hello DDJJ";
        System.out.println(str.toLowerCase());
        System.out.println(str.toUpperCase(Locale.ROOT));
    }
    public static void main10(String[] args) {
        char c = 'c';
        char[] ch = {'a','b','c','d'};
        byte b = 1;
        short s = 393;
        int a = 89;
        double d = 3.14;
        float f = 5.90f;
        Student student = new Student();
        boolean l = false;
        System.out.println(String.valueOf(c));
        System.out.println(String.valueOf(b));
        System.out.println(String.valueOf(s));
        System.out.println(String.valueOf(a));

        System.out.println(String.valueOf(d) + 0.4);
        System.out.println(String.valueOf(f));
        System.out.println(String.valueOf(l));
        System.out.println(String.valueOf(student));
        System.out.println(String.valueOf(ch));
        System.out.println(String.valueOf(ch,0,4));
    }
    public static void main9(String[] args) {
        String str = new String("   sindi dkns oso   ");//去除左右空格
        System.out.println(str.trim());
    }
    public static void main8(String[] args) {
        String str = new String("name = zhangsan age = 18");
//        String[] strings = str.split(" ");
//        for (int i = 0; i < strings.length; i++) {
//            String[] str1 = strings[i].split("=");
//            for (int j = 0; j < str1.length; j++) {
//                System.out.print(str1[j] + " ");
//            }
//        }
//        String[] strings = str.split(" ",1);//以字符regex为分割点，将字符串分割成limit组
//        for (int i = 0; i < strings.length; i++) {
//            System.out.println(strings[i]);
//        }
//        String[] strings = str.split(" |=");
//        for (String s:strings) {
//            System.out.print(s + "1");
//        }

    }
    public static void main7(String[] args) {
        String str = new String("snvisnvsdvnods");
        String str1 = str.replace('s','j');//创建一个新的字符串，字符串内容替换
        System.out.println(str1);
        System.out.println(str.replace("n", "s"));
        System.out.println(str.replaceAll("sn", "kj"));
        System.out.println(str.replaceFirst("sn", "j"));
    }
    public static void main6(String[] args) {
        String str = new String("siaisnfisnifndsvm");
        System.out.println(str.substring(6));
        System.out.println(str.substring(6, 10));//截取字符串指定区间的内容，并返回(左闭右开)
    }
    public static void main5(String[] args) {
        String str = new String("hellodosodosodsod");
//        System.out.println(str.charAt(5));
        int ret = str.indexOf('0');//返回指定字符在字符串中第一次出现的下标
        System.out.println(ret);
        System.out.println(str.indexOf('j', 1));
        System.out.println(str.indexOf('l', 2));
        System.out.println(str.indexOf("s"));
        System.out.println(str.indexOf("od", 1));
        System.out.println(str.lastIndexOf('d'));
        System.out.println(str.lastIndexOf('d', 9));
        System.out.println(str.lastIndexOf("od"));
        System.out.println(str.lastIndexOf("od", 14));
    }
    public static void main4(String[] args) {
        char[] var = new char[]{'a','b','c'};
        String str = new String(var);
        for (int i = 0; i < str.length(); i++) {
            System.out.println(str.charAt(i));//chatAt方法可以拿到字符串指定下标的字符
        }
    }
    public static void main3(String[] args) {
        String str = new String("");
    }
    public static void main2(String[] args) { // s1和s2引用的是不同对象 s1和s3引用的是同一对象
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println(s1.length());
        // 获取字符串长度---输出5
        System.out.println(s1.isEmpty());
        // 如果字符串长度为0，返回true，否则返回false }
    }
    public static void main1(String[] args) {
        String str1 = "hello";//直接赋值
        String str2 = new String("world");//通过构造方法构造
        char[] var = new char[]{'a','b','c'};//往构造方法中传入一个指向字符数组的引用
        String str3 = new String(var);

        str1.length();

        str3.toLowerCase();
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(var);


    }
}
